<?php
namespace App\Api\V1\Models;

use Illuminate\Database\Eloquent\Model;

class AdsPosition extends Model
{
    protected $table = 'ads_position';
    public $timestamps = false;

    // 添加一个广告位置
    public function addPositionItem()
    {
        $data = [
            'code' => 'index-1',
            'platform' => '0',
            'name' => 'textb',
            'description' => 'textb',
            'content' => '哈哈哈哈哈哈哈哈哈哈或或',
            'type' => '1',
        ];
        $this->code = $data['code'];
        $this->name = $data['name'];
        $this->content = $data['content'];
        $this->description = $data['description'];
        $this->type = $data['type'];
        if ($this->save()) {
            return $this->toArray();
        }
        return false;
    }

    /*
   * 编辑一个广告位置
   * */
    public function setPositionItem()
    {
        $data = [
            'ads_position_id' => '1',
            'code' => 'index_1',
            'name' => 'textb',
            'url' => '',
            'target' => '_self',
            'content' => '',
            'color' => '#ffffff',
            'begin_time' => '2018-05-01 00:00:00',
            'end_time' => '2018-05-03 23:59:59',
            'sort' => '50',
            'status' => '1'
        ];
        $res = AdsPosition::where('ads_id', 1)->update($data);
        if ($res) {
            return $this->toArray();
        }
        return false;
    }

    /*
     * 批量删除广告位置
     * */
    public function delPositionList()
    {

            $ads_id = [113, 114, 115];
            $res = AdsPosition::destroy($ads_id);
            if ($res) {
                return $this->toArray();
            }
            return false;
    }
    // 验证广告位置编号是否唯一
    public function uniquePositionCode(){

    }
    //设置广告位置状态
    public function setPositionStatus(){
        $status = 0;
        $id = 2;
        $res = AdsPosition::where('ads_id',$id)->update($status);
        if ($res){
            return $this->toArray();
        }
        return false;
    }
    /*
     * 设置广告排序位置
     * */
    public function setAdsSort(){
        $sort = 2;
        $id = 2;
        $data = ['sort'=>$sort];
        $res = AdsPosition::where('ads_id',$id)->update($data);
        if ($res){
            return $this->toArray();
        }
        return false;
    }
    public function getAdsList(){
        return $this->get()->toArray();
    }
    /*
     * 根据编号自动排序位置
     * */
    public function setAdsIndex(){
        return $this->orderBy('sort', 'asc')->get();
    }
    /*
     * 获取一个广告位置信息
     * */
    public function getPositionItem(){
        $id = 1;
        return AdsPosition::where('ads_id',$id)->select();;
    }
    /*
     * 获取广告位置列表
     * */
    public function getPositionList(){
        return $this->get()->toArray();
    }
    // 获取广告位置选择列表
    public function getPositionSelect(){
        return $this->get()->toArray();
    }
    // 根据广告位置编码获取广告列表
    public function getPositionCode(){

    }
}
